{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "41f6e456",
   "metadata": {},
   "source": [
    "# p35"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "eb05b55a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "现在是秒/时间为奇数\n",
      "1\n",
      "现在是秒/时间为奇数\n",
      "1\n",
      "现在是秒/时间为奇数\n",
      "1\n",
      "现在是秒/时间为奇数\n",
      "1\n",
      "现在是秒/时间为奇数\n"
     ]
    }
   ],
   "source": [
    "import datetime\n",
    "\n",
    "odds = [  1, 3,  5,  7,  9, 11,13,15,17,19,\n",
    "             21,23,25,27,29,31,33,35,37,39,\n",
    "             41,43,45,47,49,51,53,55,57,59] \n",
    "\n",
    "\n",
    "right_this_minute = datetime.datetime.today().second\n",
    "\n",
    "for i in range(5): \n",
    "    if right_this_minute in odds:\n",
    "        print(right_this_minute)\n",
    "        print(\"现在是秒/时间为奇数\")\n",
    "    else:\n",
    "        print(right_this_minute)\n",
    "        print(\"现在秒/时间为偶数\")\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "f70807a3",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'random' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[1;32mIn [3]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43mrandom\u001b[49m\u001b[38;5;241m.\u001b[39mrandint(\u001b[38;5;241m10\u001b[39m,\u001b[38;5;241m60\u001b[39m)\n",
      "\u001b[1;31mNameError\u001b[0m: name 'random' is not defined"
     ]
    }
   ],
   "source": [
    "random.randint(10,60)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "6def73e1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n",
      "现在是秒/时间为奇数\n",
      "4\n",
      "现在秒/时间为偶数\n",
      "9\n",
      "现在是秒/时间为奇数\n",
      "10\n",
      "现在秒/时间为偶数\n"
     ]
    },
    {
     "ename": "KeyboardInterrupt",
     "evalue": "",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m                         Traceback (most recent call last)",
      "Input \u001b[1;32mIn [4]\u001b[0m, in \u001b[0;36m<cell line: 8>\u001b[1;34m()\u001b[0m\n\u001b[0;32m     14\u001b[0m     \u001b[38;5;28mprint\u001b[39m(right_this_minute)\n\u001b[0;32m     15\u001b[0m     \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m现在秒/时间为偶数\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m---> 16\u001b[0m \u001b[43mtime\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msleep\u001b[49m\u001b[43m(\u001b[49m\u001b[43mrandom\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrandint\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m1\u001b[39;49m\u001b[43m,\u001b[49m\u001b[38;5;241;43m6\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m: "
     ]
    }
   ],
   "source": [
    "import datetime\n",
    "import time\n",
    "import random\n",
    "\n",
    "odds = [  1, 3,  5,  7,  9, 11,13,15,17,19,\n",
    "             21,23,25,27,29,31,33,35,37,39,\n",
    "             41,43,45,47,49,51,53,55,57,59] \n",
    "for i in range(5): \n",
    "    right_this_minute = datetime.datetime.today().second\n",
    "    if right_this_minute in odds:\n",
    "        print(right_this_minute)\n",
    "        print(\"现在是秒/时间为奇数\")\n",
    "    else:\n",
    "        print(right_this_minute)\n",
    "        print(\"现在秒/时间为偶数\")\n",
    "    time.sleep(random.randint(1,6))\n",
    "\n",
    "# 爬虫，爬数据，每隔5秒抓一次数据\n",
    "# 反爬虫，"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "023d2893",
   "metadata": {},
   "source": [
    "# p43实践"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "6013f276",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "unexpected EOF while parsing (2304171109.py, line 13)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  Input \u001b[1;32mIn [5]\u001b[1;36m\u001b[0m\n\u001b[1;33m    print(new_num, word, \"在啤酒墙上\"\u001b[0m\n\u001b[1;37m                                ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m unexpected EOF while parsing\n"
     ]
    }
   ],
   "source": [
    "word = \"bottles\"\n",
    "for beer_num in range(99,0,-1):\n",
    "    print(beer_num, word,\"在啤酒墙上\")\n",
    "    print(beer_num, word,\"啤酒\")\n",
    "    print(\"拿一瓶\")\n",
    "    print(\"传递它\")\n",
    "    if beer_num == 1:\n",
    "        print(\"没有更多的啤酒在啤酒墙上了，这瓶不给你，要展示的\")\n",
    "    else:\n",
    "        new_num = beer_num - 1\n",
    "        if new_num == 1:\n",
    "            word = \"bottle\"\n",
    "        print(new_num, word, \"在啤酒墙上\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "763d00a2",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
